package com.sicau.smarttraceplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicau.smarttraceplatform.entity.User;
import com.sicau.smarttraceplatform.entity.param.user.UserQueryParam;
import com.sicau.smarttraceplatform.entity.vo.PageDataVO;
import com.sicau.smarttraceplatform.mapper.UserMapper;
import com.sicau.smarttraceplatform.service.UserService;
import com.sicau.smarttraceplatform.utils.PageUtil;
import com.sicau.smarttraceplatform.utils.QueryWrapperUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2020-05-24
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    /**
     * 排序属性
     */
    private static final String[] ORDER_COLUMN = {"created"};

    @Resource
    private UserMapper userMapper;

    @Override
    public PageDataVO<User> queryUsersByCondition(UserQueryParam userQueryParam) {
        QueryWrapper<User> queryWrapper = QueryWrapperUtil.getQueryWrapper(User.class, UserQueryParam.class, userQueryParam);
        queryWrapper.orderByDesc(ORDER_COLUMN);
        Page<User> infoVOPage = new Page<>(userQueryParam.getCurrentPage(), userQueryParam.getPageSize());
        infoVOPage = userMapper.selectPage(infoVOPage, queryWrapper);
        return PageUtil.convert(infoVOPage);
    }
}
